package fileexplorer.view;

import fileexplorer.model.Directory;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: rejeev
 * Date: 5/1/13
 * Time: 10:31 PM
 * To change this template use File | Settings | File Templates.
 */
public class DirectoryIconRenderer extends DefaultTreeCellRenderer {
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
        Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        Directory directory = (Directory)node.getUserObject();
        if(leaf && directory.hasChildren){
            this.setIcon(this.getClosedIcon());
        }
        return result;
    }
}
